const CopyPlugin = require('copy-webpack-plugin');
const path = require('path');
const draw = 'node_modules/@jkyu/monet-draw/build';

const target = 'https://imonet.jdcloud.com';

module.exports = {
  configureWebpack: (config) => {
    config.plugins.push(
      new CopyPlugin([
        {
          from: path.join(draw, 'static'),
          to: 'static',
        },
      ])
    );
  },
  devServer: {
    port: 8600,
    proxy: {
      '/api': {
        target,
        ws: true,
        changeOrigin: true,
        secure: false,
        headers: {
          Host: '',
          Connection: 'keep-alive',
        },
        pathRewrite: {
          '^/api': '/api',
        },
      },
      '/geojson': {
        target,
        secure: false,
        changeOrigin: true,
        headers: {
          Host: '',
          Connection: 'keep-alive',
        },
        pathRewrite: {
          '^/geojson': '/geojson',
        },
      },
      '/oss-imonet': {
        target,
        secure: false,
        changeOrigin: true,
        headers: {
          Host: '',
          Connection: 'keep-alive',
        },
        pathRewrite: {
          '^/oss-imonet': '/oss-imonet',
        },
      },
    },
  },
};
